﻿namespace Shanda.DevFx.Security.Web.Pages
{
    using Shanda.DevFx.Core;
    using Shanda.DevFx.Security;
    using Shanda.DevFx.Security.Web;
    using System;
    using System.Web.UI.WebControls;

    public class PasswordPage : Shanda.DevFx.Security.Web.BasePage
    {
        protected Button btnSubmit;
        protected CompareValidator cvNewPassword;
        protected Label lblMessage;
        protected RequiredFieldValidator rfvConfigPassword;
        protected RequiredFieldValidator rfvNewPassword;
        protected RequiredFieldValidator rfvOldPassword;
        protected TextBox txtConfirmPassword;
        protected TextBox txtNewPassword;
        protected TextBox txtOldPassword;
        protected string userNo;
        protected ValidationSummary vsUser;

        protected virtual void btnSubmit_Click(object sender, EventArgs e)
        {
            if (!base.get_IsValid())
            {
                this.lblMessage.set_Text("请正确填写表单");
            }
            else
            {
                IAOPResult result = Securitor.UserManager.ChangePassword(this.userNo, this.txtOldPassword.get_Text(), this.txtNewPassword.get_Text());
                if (result.IsSuccess)
                {
                    this.lblMessage.set_Text("修改成功");
                }
                else
                {
                    this.lblMessage.set_Text(result.ResultDescription);
                }
            }
        }

        protected override void InitData()
        {
            base.InitData();
            this.userNo = Securitor.UserManager.GetUserNoByUserName(base.get_User().get_Identity().get_Name());
        }

        private void InitializeComponent()
        {
            this.btnSubmit.add_Click(new EventHandler(this.btnSubmit_Click));
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
        }
    }
}

